package mayor.mq.message.model;

import com.alibaba.rocketmq.client.producer.DefaultMQProducer;
import com.alibaba.rocketmq.client.producer.SendResult;
import com.alibaba.rocketmq.common.message.Message;

public class Producer {
    public static void main(String[] args) throws Exception{
        DefaultMQProducer  producer =  new DefaultMQProducer("message_producer");
        producer.setNamesrvAddr("192.168.2.246:9876;192.168.2.190:9876");
        producer.start();
        for (int i = 0; i < 10; i++) {
            try {
                Message msg = new Message("Topic1",
                        "Tag1",
                        ("信息内容" + i).getBytes());
                SendResult sendResult = producer.send(msg);
                System.out.println(sendResult);

                /**
                 * SendResult [sendStatus=SEND_OK, msgId=C0A802F600002A9F0000000000000614,
                 * messageQueue=MessageQueue [topic=TopicQuickStart, brokerName=broker-a, queueId=3], queueOffset=2]
                 *
                 *
                 */
            }catch (Exception e) {
                e.printStackTrace();
                Thread.sleep(1000);
            }
        }
        producer.shutdown();
    }
}
